package com.xxx.server.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class CaptchaConfig {
    @Bean
    public DefaultKaptcha defaultKaptcha(){
        //验证码生成器
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        //配置
        Properties properties = new Properties();
        //设置边框
        properties.setProperty("kaptcha.border","yes");
        //设置边框颜色
//        properties.setProperty("kaptcha.border.color","white");  //color: 105,179,90
        //验证码
        properties.setProperty("kaptcha.session.key","code");
        //验证码颜色，默认为黑色
        properties.setProperty("kaptcha.textproducer.font.color","blue");
        //字体样式
        properties.setProperty("kaptcha.textproducer.font.names","楷体");
        //字体大小
        properties.setProperty("kaptcha.textproducer.font.size","30");
        //验证码文本字符内容范围
        // properties.setProperty("kaptcha.textproducer.char.string","3");
        //字符长度默认为5,，
        properties.setProperty("kaptcha.textproducer.char.length","4");
        //字符间距，默认为2
        properties.setProperty("kaptcha.textproducer.char.space","4");
        //图片宽度，默认为200；
        properties.setProperty("kaptcha.image.with","100");
        //图片高度默认为40
        properties.setProperty("kaptcha.image.height","40");
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;


    }

}
